<template>
  <div class="shareContainer" ref="shareContainer">
    <!-- <div class="shareheader">
      <div class="shareheader_top">
        <div style="min-width:260px;margin: 5px 10px 18px 0px;">
          <span style="font-size: 13px; padding: 0px 8px 0px 0px">车牌号</span>
          <el-input v-model="queryparam.license_plate" placeholder="请输入车牌号" style="width: 210px; padding: 0px 8px 0px 0px">
          </el-input>
        </div>
        <div style="min-width:233px;margin: 5px 10px 18px 0px;">
          <span style="font-size: 13px; padding: 0px 8px 0px 0px">车辆类型</span>
          <el-select v-model="queryparam.vehicle_type" placeholder="请选择" style="width: 172px">
            <el-option v-for="item in caroptions" :key="item.item_code" :label="item.item_name" :value="item.item_code" :disabled="item.disabled">
            </el-option>
          </el-select>
        </div>
        <div style="min-width:219px;margin: 5px 10px 18px 0px;">
          <span style="font-size: 13px; padding: 0px 8px 0px 0px">承运商</span>
          <el-select v-model="queryparam.carrier_id" placeholder="请选择" style="width: 172px">
            <el-option v-for="item in carrierID" :key="item.id" :label="item.name" :value="item.id" :disabled="item.disabled">
            </el-option>
          </el-select>
        </div>
        <div style="min-width:100px;margin: 5px 10px 18px 0px;">
          <el-button type="primary" @click="PagequeryCar()" data-tracker="P27-1" icon="el-icon-search">查询</el-button>
          <el-button type="primary" plain @click="restequery()" data-tracker="P27-2" icon="el-icon-refresh-left">重置</el-button>
        </div>

      </div>
    </div> -->
    <div class="sharecontent">
      <!-- 头部内容 -->
      <div class="sharecontent_header">
        <div class="sharecontent_header_right">
          <el-button
            v-permission="'company_vehicle_create'"
            type="primary"
            plain
            data-tracker="P27-3"
            @click="handleClick()"
            style="margin: 0px 10px 10px 0px"
            >新增</el-button
          >
          <el-button
            v-permission="'company_vehicle_delete'"
            type="primary"
            plain
            data-tracker="P27-4"
            @click="PageDeleteCar()"
            style="margin: 0px 10px 10px 0px"
            >删除</el-button
          >
        </div>
        <div style="display: flex">
          <div>
            <el-button
              type="primary"
              size="mini"
              @click="restequery"
              style="margin: 0px 10px 0px 0px"
              >重置</el-button
            >
          </div>
          <div>
            <SettinUp
              :settype="34"
              :objSettinUpdata="objSettinUp"
              key="3"
            ></SettinUp>
          </div>
        </div>
      </div>
      <!-- 表单内容 -->
      <div class="sharecontent_content">
        <TableHeader
          ref="TableHeaderList"
          :header_data_list="header_data_list"
          :HeaderData="HeaderData"
          :propMap="propMap"
          :objheader="objheader"
          @childEvent="handleDelete"
          @orderIdNumsEvent="handleDeleteType"
          :operation_type="operation_type"
          @handleClickDetail_second="handleClickDetail_second"
          @handleClickEdit_second="handleClickEdit_second"
          particulars="finance_invoice_book_list"
          redact="finance_invoice_book_update"
        >
        </TableHeader>
        <!-- <el-table ref="multipleTable" :data="tableData" border stripe style="width: 100%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" fixed width="55"> </el-table-column>
          <el-table-column type="index" fixed label="序号" width="55"></el-table-column>
          <el-table-column fixed prop="license_plate" label="车牌号" width="150">
          </el-table-column>
          <el-table-column prop="vehicle_type" label="车辆类型" width="200">
          </el-table-column>
          <el-table-column prop="vehicle_source" label="来源" width="200">
          </el-table-column>
          <el-table-column prop="vehicle_width" label="车宽" width="200">
          </el-table-column>
          <el-table-column prop="vehicle_length" label="车长" width="200">
          </el-table-column>
          <el-table-column prop="vehicle_height" label="车长" width="200">
          </el-table-column>
          <el-table-column prop="vehicle_axle_count" label="车轴数" width="200">
          </el-table-column>
          <el-table-column prop="vehicle_load" label="载重" width="200">
          </el-table-column>
          <el-table-column prop="space_size" label="净空" width="200">
          </el-table-column>
          <el-table-column prop="wagon_box_length" label="车厢长度" width="200">
          </el-table-column>
          <el-table-column prop="wagon_box_width" label="车厢宽度" width="200">
          </el-table-column>
          <el-table-column prop="wagon_box_height" label="车厢高" width="200">
          </el-table-column>
          <el-table-column prop="wagon_box_height" label="车厢宽度" width="200">
          </el-table-column>
          <el-table-column prop="temp_control_type" label="温控要求" width="200">
          </el-table-column>
          <el-table-column prop="vehicle_picture" label="车辆照片" width="200">
            <template slot-scope="scope">
              <img :src="
                  scope.row.vehicle_picture ? scope.row.vehicle_picture : ''
                " style="width: 50px" />
            </template>
          </el-table-column>
          <el-table-column prop="vehicle_license" label="行驶证" width="200">
            <template slot-scope="scope">
              <img :src="
                  scope.row.vehicle_license ? scope.row.vehicle_license : ''
                " style="width: 50px" />
            </template>
          </el-table-column>
          <el-table-column prop="operation_license" label="运营证" width="200">
            <template slot-scope="scope">
              <img :src="
                  scope.row.operation_license ? scope.row.operation_license : ''
                " style="width: 50px" />
            </template>
          </el-table-column>
          <el-table-column prop="carrier_name" label="承运商" width="200">
          </el-table-column>
          <el-table-column prop="status" label="状态" width="200">
          </el-table-column>
          <el-table-column prop="remark" label="备注" width="200">
          </el-table-column>
          <el-table-column prop="shared" label="对外共享" width="200">
          </el-table-column>
          <el-table-column prop="shared_website_info" label="共享网点" width="200">
          </el-table-column>
          <el-table-column prop="temp_device_info" label="温度计" width="200">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button v-permission="'company_vehicle_detail'" @click="handleClick(scope.row, '1')" data-tracker="P27-5" type="text" size="small">查看</el-button>
              <el-button v-permission="'company_vehicle_update'" type="text" size="small" data-tracker="P27-6" @click="handleClick(scope.row, '2')">修改</el-button>
            </template>
          </el-table-column>
        </el-table> -->
      </div>
      <div class="sharecontent_header_left">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryparam.page"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="queryparam.page_size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
      <!-- 弹框内容 -->
      <div>
        <el-dialog
          :title="title_name"
          :close-on-click-modal="false"
          :visible.sync="dialogVisible"
          width="63%"
        >
          <div>
            <el-form
              :inline="true"
              class="demo-form-inline"
              label-width="120px"
              :rules="rules"
              ref="ruleForm"
              :model="ruleForm"
            >
              <el-form-item label="车牌号" prop="license_plate">
                <el-input
                  placeholder="车牌号"
                  v-model="ruleForm.license_plate"
                ></el-input>
              </el-form-item>
              <el-form-item label="车辆类型" prop="vehicle_type">
                <el-select
                  v-model="ruleForm.vehicle_type"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in caroptions"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="来源" prop="vehicle_source">
                <el-select
                  v-model="ruleForm.vehicle_source"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in source_options"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="车宽">
                <el-input
                  v-model="ruleForm.vehicle_width"
                  placeholder="车宽cm"
                ></el-input>
              </el-form-item>
              <el-form-item label="车长" prop="vehicle_length">
                <el-input
                  v-model="ruleForm.vehicle_length"
                  placeholder="车长cm"
                ></el-input>
              </el-form-item>
              <el-form-item label="车高">
                <el-input
                  v-model="ruleForm.vehicle_height"
                  placeholder="车长cm"
                ></el-input>
              </el-form-item>
              <el-form-item label="车轴数" prop="vehicle_axle_count">
                <el-select
                  v-model="ruleForm.vehicle_axle_count"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in axleoptions"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="载重" prop="vehicle_load">
                <el-input
                  v-model="ruleForm.vehicle_load"
                  placeholder="载重"
                ></el-input>
              </el-form-item>
              <el-form-item label="净空" prop="space_size">
                <el-input
                  v-model="ruleForm.space_size"
                  placeholder="净空"
                ></el-input>
              </el-form-item>
              <el-form-item label="车厢长度">
                <el-input
                  v-model="ruleForm.wagon_box_length"
                  placeholder="车厢长度"
                ></el-input>
              </el-form-item>
              <el-form-item label="车厢宽度">
                <el-input
                  v-model="ruleForm.wagon_box_width"
                  placeholder="车厢宽度"
                ></el-input>
              </el-form-item>
              <el-form-item label="车厢高度">
                <el-input
                  v-model="ruleForm.wagon_box_height"
                  placeholder="车厢高度"
                ></el-input>
              </el-form-item>
              <el-form-item label="温控要求" prop="temp_control_type">
                <el-select
                  v-model="ruleForm.temp_control_type"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in temoptions"
                    :key="item.item_code"
                    :label="item.item_name"
                    :value="item.item_code"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="车辆照片">
                <el-upload
                  class="upload-demo"
                  ref="add-upload"
                  action
                  multiple
                  :auto-upload="false"
                  :file-list="ruleForm.vehicle_picture"
                  :on-change="
                    (file, fileList) => {
                      handleChange(file, fileList, 6);
                    }
                  "
                  :on-remove="
                    (file, fileList) => {
                      removeChange(file, fileList, 6);
                    }
                  "
                >
                  <el-button
                    slot="trigger"
                    size="small"
                    icon="el-icon-upload2"
                    style="width: 172px"
                  >
                    上传文件</el-button
                  >
                </el-upload>
              </el-form-item>
              <el-form-item label="行车证">
                <el-upload
                  class="upload-demo"
                  ref="add-upload"
                  action
                  multiple
                  :auto-upload="false"
                  :file-list="ruleForm.vehicle_license"
                  :on-change="
                    (file, fileList) => {
                      handleChange(file, fileList, 7);
                    }
                  "
                  :on-remove="
                    (file, fileList) => {
                      removeChange(file, fileList, 7);
                    }
                  "
                >
                  <el-button
                    slot="trigger"
                    size="small"
                    icon="el-icon-upload2"
                    style="width: 172px"
                  >
                    上传文件</el-button
                  >
                </el-upload>
              </el-form-item>
              <el-form-item label="运营证">
                <el-upload
                  class="upload-demo"
                  ref="add-upload"
                  action
                  multiple
                  :auto-upload="false"
                  :file-list="ruleForm.operation_license"
                  :on-change="
                    (file, fileList) => {
                      handleChange(file, fileList, 8);
                    }
                  "
                  :on-remove="
                    (file, fileList) => {
                      removeChange(file, fileList, 8);
                    }
                  "
                >
                  <el-button
                    slot="trigger"
                    size="small"
                    icon="el-icon-upload2"
                    style="width: 172px"
                  >
                    上传文件</el-button
                  >
                </el-upload>
              </el-form-item>
              <el-form-item
                label="承运商"
                v-if="ruleForm.vehicle_source == '1'"
                prop="carrier_id"
              >
                <el-select
                  v-model="ruleForm.carrier_id"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in carrierID"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="温度计设备">
                <el-select
                  v-model="ruleForm.temp_device"
                  multiple
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in threoptionsbox"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="Gps厂商授权">
                <el-select
                  v-model="ruleForm.position_firm_auth_id"
                  placeholder="请选择"
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in GpsManufacturer"
                    :key="item.key"
                    :label="item.value"
                    :value="item.key"
                    :disabled="item.disabled"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="对外共享">
                <el-switch
                  v-model="ruleForm.shared"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  active-value="1"
                  inactive-value="0"
                >
                </el-switch>
              </el-form-item>
             
              <el-form-item
                label="共享网点"
                v-if="ruleForm.shared == '1'"
                prop="shared_website"
              >
                <el-select
                  v-model="ruleForm.shared_website"
                  placeholder="请选择"
                  multiple
                  style="width: 172px"
                >
                  <el-option
                    v-for="item in originList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="备注">
                <el-input
                  v-model="ruleForm.remark"
                  placeholder="备注"
                ></el-input>
              </el-form-item>
              <el-form-item label="是否启用" prop="status">
                <el-switch
                  v-model="ruleForm.status"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  active-value="0"
                  inactive-value="1"
                >
                </el-switch>
              </el-form-item>
            </el-form>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button
              :data-tracker="orderstate == '0' ? 'P27-8' : 'P27-10'"
              @click="cenclelist()"
              >取 消</el-button
            >
            <!-- 代表创建的确定 -->
            <el-button
              type="primary"
              data-tracker="P27-7"
              @click="PageAddCar('ruleForm')"
              v-if="orderstate == '0'"
              >确 定
            </el-button>
            <!-- 修改的确定 -->
            <el-button
              type="primary"
              data-tracker="P27-9"
              @click="PageEditCar('ruleForm')"
              v-if="orderstate == '2'"
              >确 定
            </el-button>
          </span>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import TableHeader from "@/page/orderform/components/TableHeader/tableheader.vue";
import SettinUp from "@/page/orderform/components/settingUp/settingUp.vue";
// 通过车辆的来源进行判断是否是内部车辆还是外部车辆
import {
  EditCar,
  DeleteCar,
  DetailsCar,
  AddCar,
  queryCar,
  thermometerbox, //温度计获取
  position_firm_auth_options,//Gps 厂商授权
} from "@/api/information";
import {
  uploading,
  PagewebsiteList,
  allcarrierID,
  dictionanryList,
} from "../common/common";
export default {
  components: { TableHeader, SettinUp },
  data() {
    return {
      // 组织管理的字段
      originList: [],
      title_name: "车辆管理",
      // 创建车辆的列表字段
      ruleForm: {
        license_plate: "", //车牌
        vehicle_type: "", //车型
        vehicle_source: "", //来源 0 内部 1 外部
        vehicle_width: "", //车宽
        vehicle_length: "", //车长
        vehicle_height: "", //车高
        vehicle_axle_count: "", //车轴数
        vehicle_load: "", //载重KG
        space_size: "", //净空立方厘米
        wagon_box_length: "", //车厢长cm
        wagon_box_width: "", //车厢宽
        wagon_box_height: "", //车厢高
        temp_control_type: "", //温控要求
        vehicle_picture: [], //车辆照片
        vehicle_license: [], //行驶证
        operation_license: [], //运营证
        carrier_id: "", //承运商id
        status: "0", //状态 0 启用 1 禁用
        remark: "", //备注
        shared: "0", //对外共享
        shared_website: [], //共享网点
        temp_device: [], //温度计设备
        position_firm_auth_id:"",//Gps 厂商授权
      },
      rules: {
        license_plate: [
          { required: true, message: "请填写车牌", trigger: "blur" },
          {
            required: true,
            pattern:
              /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DABCEFGHJK]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/,
            message: "请输入正确的车牌号",
            trigger: "blur",
          },
        ],
        vehicle_source: [
          { required: true, message: "请填写来源", trigger: "blur" },
        ],
        vehicle_type: [
          { required: true, message: "请填写车型", trigger: "blur" },
        ], //车型
        // vehicle_length: [
        //   { required: true, message: "请填写车长", trigger: "blur" },
        // ], //车长
        // vehicle_axle_count: [
        //   { required: true, message: "请填写车轴数", trigger: "blur" },
        // ], //车轴数
        // vehicle_load: [
        //   { required: true, message: "请填写载重 ", trigger: "blur" },
        // ], // 载重
        // space_size: [
        //   { required: true, message: "请填写净空 ", trigger: "blur" },
        // ], //净空
        temp_control_type: [
          { required: true, message: "请填写温控要求 ", trigger: "blur" },
        ], //温控要求
        carrier_id: [
          { required: true, message: "请填写承运商 ", trigger: "blur" },
        ], //承运商的id
        shared_website: [
          { required: true, message: "请填写共享网点 ", trigger: "blur" },
        ], //承运商的id
      },
      tableData: [],
      queryparam: {
        // license_plate: "", //车牌号
        // vehicle_type: "", //车辆类型
        // carrier_id: "", //承运商id
        page: 1,
        page_size: 20,
      },
      total: 0, //总条数
      currentPage4: 1,
      deletparam: {
        id: [], //多选删的id
      },
      consignerID: "", //发货人的ID
      orderstate: "", //选着的是创建还是修改
      dialogVisible: false, //判断弹框显示隐藏
      source_options: [], //车辆来源
      caroptions: [
        //车辆类型
        {
          value: "金杯",
          label: "金杯",
        },
        {
          value: "4.2米",
          label: "4.2米",
        },
        {
          value: "7.6米",
          label: "7.6米",
        },
        {
          value: "9.6米",
          label: "9.6米",
        },
        {
          value: "17米",
          label: "17米",
        },
        {
          value: "冷藏车",
          label: "冷藏车",
        },
      ],
      temoptions: [], //温控要求
      axleoptions: [], //车轴数
      // 承运商ID
      carrierID: [],
      // 温度计设备
      threoptionsbox: [],
      // maxheight: 400,
      // ==========
      header_data_list: [],
      propMap: {},
      obj_list: {},
      HeaderData: [],
      waybillIdNums: [],
      totalPage: 0,
      operation_type: 1,
      GpsManufacturer:[]
    };
  },
  mounted() {
    // 获取组织接口
    this.siteList();
    // 承运商
    this.pageCarrierID();
    // 车辆列表
    this.PagequeryCar();
    // 数据字典
    this.dicList();
    // 温度计box
    this.Pagethermometerbox();
    this.Objposition_firm_auth_options()
  },
  methods: {
    // 温度计设备
    Pagethermometerbox() {
      var pame = {
        name: "",
      };
      thermometerbox(pame).then((res) => {
        var res = res.data;
        this.threoptionsbox = res;
      });
    },
    // 数据字典
    dicList() {
      var param = [
        "temp_control",
        "vehicle_axle",
        "vehicle_sour",
        "vehicle_type",
      ];
      dictionanryList(param).then((res) => {
        var res = res.data;
        // 温控要求
        this.temoptions = res.list.temp_control;
        // 车轴数
        this.axleoptions = res.list.vehicle_axle;
        // 车辆来源
        this.source_options = res.list.vehicle_sour;
        // 车辆类型
        this.caroptions = res.list.vehicle_type;
      });
    },
    // 获取多选删除的id号
    handleSelectionChange(val) {
      var deleid = [];
      for (var i = 0; i < val.length; i++) {
        deleid.push(val[i].id);
      }
      this.deletparam.id = deleid;
    },
    // 获取id
    handleClick(row, type) {
      if (row == undefined) {
        this.title_name = "创建车辆";
        this.orderstate = "0";
        this.openpop();
        this.clearList();
      } else if (row != "" && type == 1) {
        this.title_name = "查看车辆";
        this.orderstate = "";
        this.openpop();
        this.PageDetailsCar(row.id);
      } else if (row != "" && type == 2) {
        this.title_name = "修改车辆";
        this.orderstate = "2";
        this.consignerID = row.id;
        this.openpop();
        this.PageDetailsCar(row.id);
      }
    },
    // 分页功能
    // 一页有多少条
    handleSizeChange(val) {
      this.queryparam.page_size = val;
      //  数据列表接口
      this.PagequeryCar();
    },
    // 当前第几页
    handleCurrentChange(val) {
      this.queryparam.page = val;
      //  数据列表接口
      this.PagequeryCar();
    },
    // 图片上传功能
    handleChange(file, fileList, type) {
      var filelist = file.raw; //文件
      var filename = file.raw.uid + file.raw.name; //通过 uid和name组成文件的名字
      uploading(filelist, filename, type).then((result) => {
        var resname = result.name;
        var resType = resname.split("/")[0];
        var filehttp = "http://oss.dushisc.com/";
        switch (resType) {
          case "6":
            this.ruleForm.vehicle_picture.push({
              name: filehttp + result.name,
            });

            break;
          case "7":
            // 上传多个列表
            this.ruleForm.vehicle_license.push({
              name: filehttp + result.name,
            });
            break;
          case "8":
            this.ruleForm.operation_license.push({
              name: filehttp + result.name,
            });
            break;
        }
      });
    },
    removeChange(file, fileList, type) {
      switch (type) {
        case 6:
          if (this.ruleForm.vehicle_picture.length > 0) {
            for (var i = 0; i < this.ruleForm.vehicle_picture.length; i++) {
              if (this.ruleForm.vehicle_picture[i].uid == file.uid) {
                this.ruleForm.vehicle_picture.splice(i, 1);
              }
            }
          }

          break;
        case 7:
          if (this.ruleForm.vehicle_license.length > 0) {
            for (var i = 0; i < this.ruleForm.vehicle_license.length; i++) {
              if (this.ruleForm.vehicle_license[i].uid == file.uid) {
                this.ruleForm.vehicle_license.splice(i, 1);
              }
            }
          }
          break;
        case 8:
          if (this.ruleForm.operation_license.length > 0) {
            for (var i = 0; i < this.ruleForm.operation_license.length; i++) {
              if (this.ruleForm.operation_license[i].uid == file.uid) {
                this.ruleForm.operation_license.splice(i, 1);
              }
            }
          }
          break;
      }
    },
    // 组织管理页面
    siteList() {
      PagewebsiteList("0").then((res) => {
        this.originList = res.data;
      });
    },
    // 承运商管理id
    pageCarrierID() {
      allcarrierID().then((res) => {
        var res = res.data;
        this.carrierID = res;
      });
    },
    // 编辑车辆
    PageEditCar(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          var picturename =
            this.ruleForm.vehicle_picture.length == 0
              ? ""
              : this.ruleForm.vehicle_picture[0].name;

          var licensename =
            this.ruleForm.vehicle_license.length == 0
              ? ""
              : this.ruleForm.vehicle_license[0].name;

          var operationname =
            this.ruleForm.operation_license.length == 0
              ? ""
              : this.ruleForm.operation_license[0].name;
          var param = {
            id: this.consignerID,
            license_plate: this.ruleForm.license_plate,
            vehicle_type: this.ruleForm.vehicle_type,
            vehicle_source: this.ruleForm.vehicle_source,
            vehicle_width: this.ruleForm.vehicle_width,
            vehicle_length: this.ruleForm.vehicle_length,
            vehicle_height: this.ruleForm.vehicle_height,
            vehicle_axle_count: this.ruleForm.vehicle_axle_count,
            vehicle_load: this.ruleForm.vehicle_load,
            space_size: this.ruleForm.space_size,
            wagon_box_length: this.ruleForm.wagon_box_length,
            wagon_box_width: this.ruleForm.wagon_box_width,
            wagon_box_height: this.ruleForm.wagon_box_height,
            temp_control_type: String(this.ruleForm.temp_control_type),
            vehicle_picture: String(picturename),
            vehicle_license: String(licensename),
            operation_license: String(operationname),
            carrier_id: String(this.ruleForm.carrier_id),
            status: this.ruleForm.status,
            remark: this.ruleForm.remark,
            shared: String(this.ruleForm.shared),
            shared_website: this.ruleForm.shared_website,
            temp_device: this.ruleForm.temp_device, //温度计设备
            position_firm_auth_id:this.ruleForm.position_firm_auth_id
          };
          EditCar(param).then((res) => {
            if (res.code == 10000) {
              this.closepop();
              this.PagequeryCar();
              this.$message({
                message: "修改数据成功",
                type: "success",
              });
            } else {
              this.$message({
                message: res.message,
                type: "warning",
              });
            }
          });
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    },
    // 删除车辆
    PageDeleteCar() {
      var param = {
        id: this.waybillIdNums,
      };
      DeleteCar(param).then((res) => {
        if (res.code == 10000) {
          this.PagequeryCar();
          this.$message({
            message: "删除数据成功",
            type: "success",
          });
        }
      });
    },
    // 车辆详情
    PageDetailsCar(id) {
      var params = {
        id: id,
      };
      DetailsCar(params).then((res) => {
        var res = res.data;
        var picturelist = [];
        if (res.vehicle_picture == "") {
          picturelist = [];
        } else {
          picturelist.push({ name: [res.vehicle_picture] });
        }
        var licenselist = [];
        if (res.vehicle_license == "") {
          licenselist = [];
        } else {
          licenselist.push({ name: [res.vehicle_license] });
        }
        var operation = [];
        if (res.operation_license == "") {
          operation = [];
        } else {
          operation.push({ name: [res.operation_license] });
        }
        var tepmList = [];
        if (res.temp_device_info != null) {
          res.temp_device_info.forEach((res) => {
            tepmList.push(res.id);
          });
        }
        var sharedList = [];
        if (res.shared_website_info != null) {
          res.shared_website_info.forEach((res) => {
            sharedList.push(res.id);
          });
        } else {
          sharedList = [];
        }

        this.ruleForm.license_plate = res.license_plate; //车牌
        this.ruleForm.vehicle_type = res.vehicle_type; //车型
        this.ruleForm.vehicle_source = res.vehicle_source; //来源 0 内部 1 外部
        this.ruleForm.vehicle_width = res.vehicle_width; //车宽
        this.ruleForm.vehicle_length = res.vehicle_length; //车长
        this.ruleForm.vehicle_height = res.vehicle_height; //车高
        this.ruleForm.vehicle_axle_count = res.vehicle_axle_count; //车轴数
        this.ruleForm.vehicle_load = res.vehicle_load; //载重KG
        this.ruleForm.space_size = res.space_size; //净空立方厘米
        this.ruleForm.wagon_box_length = res.wagon_box_length; //车厢长cm
        this.ruleForm.wagon_box_width = res.wagon_box_width; //车厢宽
        this.ruleForm.wagon_box_height = res.wagon_box_height; //车厢高
        this.ruleForm.temp_control_type = res.temp_control_type; //温控要求
        this.ruleForm.vehicle_picture = picturelist;
        this.ruleForm.vehicle_license = licenselist;
        this.ruleForm.operation_license = operation;
        this.ruleForm.carrier_id = Number(res.carrier_id); //承运商id
        this.ruleForm.status = res.status; //状态 0 启用 1 禁用
        this.ruleForm.remark = res.remark; //备注
        this.ruleForm.shared = String(res.shared); //对外共享
        this.ruleForm.temp_device = tepmList;
        this.ruleForm.shared_website = sharedList;
        this.ruleForm.position_firm_auth_id = res.position_firm_auth_id +""
      });
    },
    // 创建车辆信息
    PageAddCar(formName) {
      this.$refs[formName].validate((valid) => {
        // console.log(typeof this.ruleForm.shared_website);
        if (valid) {
          var picturename =
            this.ruleForm.vehicle_picture.length == 0
              ? ""
              : this.ruleForm.vehicle_picture[0].name;

          var licensename =
            this.ruleForm.vehicle_license.length == 0
              ? ""
              : this.ruleForm.vehicle_license[0].name;

          var operationname =
            this.ruleForm.operation_license.length == 0
              ? ""
              : this.ruleForm.operation_license[0].name;
          var param = {
            license_plate: this.ruleForm.license_plate, //车牌
            vehicle_type: this.ruleForm.vehicle_type, //车型
            vehicle_source: this.ruleForm.vehicle_source, //来源 0 内部 1 外部
            vehicle_width: this.ruleForm.vehicle_width, //车宽
            vehicle_length: this.ruleForm.vehicle_length, //车长
            vehicle_height: this.ruleForm.vehicle_height, //车高
            vehicle_axle_count: this.ruleForm.vehicle_axle_count, //车轴数
            vehicle_load: this.ruleForm.vehicle_load, //载重KG
            space_size: this.ruleForm.space_size, //净空立方厘米
            wagon_box_length: this.ruleForm.wagon_box_length, //车厢长cm
            wagon_box_width: this.ruleForm.wagon_box_width, //车厢宽
            wagon_box_height: this.ruleForm.wagon_box_height, //车厢高
            temp_control_type: String(this.ruleForm.temp_control_type), //温控要求
            vehicle_picture: String(picturename), //车辆照片
            vehicle_license: String(licensename), //行驶证
            operation_license: String(operationname), //运营证
            carrier_id: String(this.ruleForm.carrier_id), //承运商id
            status: this.ruleForm.status, //状态 0 启用 1 禁用
            remark: this.ruleForm.remark, //备注
            shared: this.ruleForm.shared, //对外共享
            shared_website: this.ruleForm.shared_website, //共享网点
            temp_device: this.ruleForm.temp_device, //温度计设备
            position_firm_auth_id:this.ruleForm.position_firm_auth_id
          };
          AddCar(param).then((res) => {
            if (res.code == 10000) {
              this.closepop();
              this.PagequeryCar();
              this.$message({
                message: "创建数据成功",
                type: "success",
              });
            } else {
              this.$message({
                message: res.message,
                type: "warning",
              });
            }
          });
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    },
    // 查询车辆
    PagequeryCar() {
      var querlist = {
        // license_plate: this.queryparam.license_plate, //车牌号
        // vehicle_type: this.queryparam.vehicle_type, //车辆类型
        // carrier_id: String(this.queryparam.carrier_id), //承运商id
        page: this.queryparam.page,
        page_size: this.queryparam.page_size,
        header_id: 34 + "",
      };
      queryCar(querlist).then((res) => {
        this.orders = res.data.list || [];
        this.orders.unshift({});
        this.header_data_list = this.orders;
        this.HeaderData = res.data.item_list;
        this.Fntransformation(this.HeaderData);
        this.total = res.data.pagination.total;
      });
    },
    // 处理数据函数
    DataState(res) {
      res.forEach((item) => {
        let branch_name_list = [];
        if (item.shared_website_info != null) {
          for (var j = 0; j < item.shared_website_info.length; j++) {
            branch_name_list.push(item.shared_website_info[j].name + "/");
          }
        }
        item.shared_website_info = branch_name_list;
        var tempName = [];
        if (item.temp_device_info != null) {
          item.temp_device_info.forEach((res) => {
            tempName.push(res.name + "/");
          });
        }
        item.temp_device_info = tempName;
        item.status = item.status === "0" ? "启用" : "禁用";
        item.shared = item.shared == "0" ? "不对外共享" : "对外共享";
        item.vehicle_source =
          item.vehicle_source == "0" ? "内部车辆" : "外部车辆";
        switch (item.vehicle_type) {
          case "0":
            item.vehicle_type = "金杯";
            break;
          case "1":
            item.vehicle_type = "4.2米";
            break;
          case "2":
            item.vehicle_type = "7.6米";
            break;
          case "3":
            item.vehicle_type = "9.6米";
            break;
          case "4":
            item.vehicle_type = "17米";
            break;
          case "5":
            item.vehicle_type = "冷藏车";
            break;
        }
        switch (item.vehicle_axle_count) {
          case "0":
            item.vehicle_axle_count = "2轴";
            break;
          case "1":
            item.vehicle_axle_count = "3轴";
            break;
          case "2":
            item.vehicle_axle_count = "4轴";
            break;
        }
        switch (item.temp_control_type) {
          case "0":
            item.temp_control_type = "冷冻(-15 ~ -30)";
            break;
          case "1":
            item.temp_control_type = "阴凉(15 ~ 25)";
            break;
          case "2":
            item.temp_control_type = "冷藏(2 ~ 8)";
            break;
          case "3":
            item.temp_control_type = "常温(0 ~ 30)";
            break;
          case "4":
            item.temp_control_type = "低温( -20 ~ -80 )";
            break;
        }
      });
      this.tableData = res;
    },
    // 取消数据
    cenclelist() {
      this.closepop();
      this.clearList();
    },
    // 关闭弹框的函数
    closepop() {
      this.dialogVisible = false;
    },
    openpop() {
      this.dialogVisible = true;
    },
    // 清空数据
    clearList() {
      this.ruleForm = {
        license_plate: "", //车牌
        vehicle_type: "", //车型
        vehicle_source: "", //来源 0 内部 1 外部
        vehicle_width: "", //车宽
        vehicle_length: "", //车长
        vehicle_height: "", //车高
        vehicle_axle_count: "", //车轴数
        vehicle_load: "", //载重KG
        space_size: "", //净空立方厘米
        wagon_box_length: "", //车厢长cm
        wagon_box_width: "", //车厢宽
        wagon_box_height: "", //车厢高
        temp_control_type: "", //温控要求
        vehicle_picture: [], //车辆照片
        vehicle_license: [], //行驶证
        operation_license: [], //运营证
        carrier_id: "", //承运商id
        status: "0", //状态 0 启用 1 禁用
        remark: "", //备注
        shared: "0", //对外共享
        shared_website: [], //共享网点
        temp_device: [], //温度计设备
      };
    },
    // 重置数据
    restequery() {
      // this.queryparam.license_plate = "";
      // this.queryparam.vehicle_type = "";
      // this.queryparam.carrier_id = "";
      // this.PagequeryCar();
      this.$refs.TableHeaderList.childMethod();
      this.queryparam.page = 1;
    },
    objheader(obj) {
      var data = {
        header_id: 34 + "",
        ...obj,
        page: this.queryparam.page,
        page_size: this.queryparam.page_size,
      };
      this.obj_list = obj;
      queryCar(data).then((res) => {
        this.header_data_list = res.data.list;
        if (res.code === 10000 && res.data.list !== null) {
          this.header_data_list.unshift({});
          this.total = res.data.pagination.total;
        } else {
          this.header_data_list = [{}];
          this.paginations.total = 0;
          this.orderslength = 0;
          this.total = res.data.pagination.total;
        }
      });
    },
    Fntransformation(obj) {
      const result = {};
      for (const prop in obj) {
        if (obj.hasOwnProperty(prop)) {
          if (obj[prop].send_name !== "") {
            result[obj[prop].name] = obj[prop].show_name;
          } else {
            result[obj[prop].name] = obj[prop].name;
          }
        }
      }
      this.propMap = result;
    },
    handleDelete(index, id, type) {
      this.handleJumpDetail(id);
    },
    handleDeleteType(value) {
      this.waybillIdNums = value;
    },
    handleClickDetail_second(val) {
      this.handleClick(val, "1");
    },
    handleClickEdit_second(val) {
      this.handleClick(val, "2");
    },
    objSettinUp() {
      this.PagequeryCar();
    },
    Objposition_firm_auth_options() {
       var param = {}
       position_firm_auth_options(param).then((res)=>{
        this.GpsManufacturer = res.data.options
         console.log(res,"res res")
       })
    }
  },
};
</script>

<style lang="less" scoped>
.shareContainer {
  padding: 10px 15px;
  background-color: #fff;

  .shareheader {
    background: white;

    .shareheader_top {
      display: flex;
      flex-wrap: wrap;
    }
  }

  .sharecontent_header_left {
    display: flex;
    justify-content: flex-end;
    margin: 10px 0px 0px 0px;
  }

  // 内容
  .sharecontent {
    background: white;

    // 头部内容
    .sharecontent_header {
      display: flex;
      justify-content: space-between;
      /* .sharecontent_header_right {
          display: inline-block;
        } */
    }

    // 表单内容
    .sharecontent_content {
    }
  }
}
</style>